home *** CD-ROM | disk | FTP | other *** search
- Path: loki.tor.hookup.net!news
- From: David Williams <dwilliam@micromedia.on.ca>
- Newsgroups: comp.lang.c
- Subject: Re: Q: "Overlapping Objects"
- Date: Tue, 16 Apr 1996 09:22:22 -0400
- Organization: Micromedia Limited
- Message-ID: <31739F0E.69B6@micromedia.on.ca>
- References: <31714280.201A@micromedia.on.ca> <4ks0lo$b1n@inet-nntp-gw-1.us.oracle.com>
- NNTP-Posting-Host: keeper.mmltd.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- Just to clarify what I meant:
-
- Given
-
- char s[]="abcdefghijklmnop";
- char *sp1=&s[2];
- char *sp2=&s[4];
-
- if you strcpy(sp1,sp2) [not strcat(), as below], will the results be
- as expected ("abefghijklmnop"), or will there be problems because the copy
- is copying over part of what it was originally copying from?
-
- William Kaufman wrote:
- >
- > In article <31714280.201A@micromedia.on.ca> Richard Steadman
- > <rsteadma@micromedia.on.ca> writes:
- > ] Hello.
- > ]
- > ] I have a question which is quite simple, but I can't seem to find
- > ] the right answer anywhere.
- > ]
- > ] I'm trying to figure out when it is necessary to use the memmove()
- > ] function when copying strings. K&R and the man page says to use it
- > ] when the "objects overlap". But I can't find a formal definition
- > ] for this phrase (it's not in the FAQ either -- I checked!).
- >
- > If you've got two pointers into the same piece of memory, they
- > overlap if either pointer is in the middle of the other's region (i.e.,
- > between the other pointer and that pointer plus the size you're
- > copying).
- >
- > ] Here's the scenario: I have a string, and want to copy the tail of
- > ] it to an earlier part of the string. The two pieces are *not*
- > ] overlappng when the function is called, but they may be when the
- > ] copy is finished.
- > ]
- > ] Given this, it safe to use strcat() instead of memmove()?
- >
- > I'm not sure I understand--they either overlap or they don't, and
- > asking _at what time_ fixed chunks of memory overlap doesn't make sense
- > to me. But I think your answer is "No".
- >
- > -- Bill K.
- >
- > Bill Kaufman | "I mean ... it's not even been a two-and-two-make-
- > wkaufman@us.oracle.com | five sort of day, it's more like a two-and-two-
- > | make ... *fish* ..." -- "Cages", Dave McKean
-